#include "funduspreprocessing.h"

int main(int argc, char *argv[]){
  std::string program = argv[0];
  std::vector<std::string> args(argv, argv+argc);
  if (argc<2) pip::error(program, "\nUsage: funduspreprocessing filename -pip::Color c -medianwidth m\n"
		    "Performs pip::Color fundus image preprocessing,\n selecting pip::Color channel c "
		    "('R','G' or 'B')\n and using a median of width m.\n");

  //get filename, pip::Color and medianwidth from command line
  std::string filename = argv[1];
  char Color = 'R';
  pip::getScalarArg(args, "-Color", Color);
  if(Color != 'R' &&
     Color != 'G' &&
     Color != 'B'){
       pip::error(program, "Not a valid Color channel; use 'R', 'G', or 'B'\n");
    return 1;
  }
  int medianwidth = 1;
  pip::getScalarArg(args, "-medianwidth", medianwidth);
  if(medianwidth<0){
    pip::error(program, "Not a valid median width; use an integer>0\n");
    return 1;
  }

  pip::Image<pip::Color<unsigned char> > imIn;

  if (!importFile(imIn,filename))
    pip::error(program, "Error reading input file (must be 2D RGB pip image)\n");

  pip::Image<float> imOut(imIn.dimension());
  PreProcessFundus<float> ppf;

  ppf.setColorChannel(Color);
  ppf.setMedianWidth(medianwidth);
  ppf.run(imIn,imOut);

  // save the result image
  if(!exportFile(imOut,"fundus_prepro.pip")){
    pip::error(program, "Not able to save image on disc...\n");
    return 1;
  }
  std::cout<<"\a";
  return 0;
}
